package cn.jltx.abslistviewadapterdemo;

import android.util.SparseArray;
import android.view.View;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/05/04.
 *         复用Adapter里面的子View的辅助类
 */

public class ViewHolderUtils {

    public static <T extends View> T get(View view,int id){
        SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
        if (null == viewHolder) {
            viewHolder = new SparseArray<View>();
            view.setTag(viewHolder);
        }

        View childView = viewHolder.get(id);
        if (null == childView) {
            childView = view.findViewById(id);
            viewHolder.put(id, childView);
        }

        return (T) childView;
    }
}
